
import UIKit
import SnapKit


class AssistantCell : UICollectionViewCell{
    var assistant: Assistant!
    func bindViewModel(_ assistant: Assistant) {
        avatarImageView.kf.setImage(with: URL(string: assistant.cover))
        numbersleLabel.text = assistant.users
        //通过富文本来设置行间距
        let paraph = NSMutableParagraphStyle()
        //将行间距设置为28
        paraph.lineSpacing = 8
        //样式属性集合
        let attributes = [NSAttributedString.Key.font:UIFont.systemFont(ofSize: 12),NSAttributedString.Key.foregroundColor:UIColor.white,
                          NSAttributedString.Key.paragraphStyle: paraph]
        subtitleLabel.attributedText = NSAttributedString(string: assistant.subTitle, attributes: attributes)
        nameLabel.text = assistant.title
        chatButton.setTitle(assistant.jumpTitle, for: .normal)
    }
    
    
    var avatarImageView: UIImageView = {
        let cover = UIImageView()
        cover.layer.cornerRadius = 8
        cover.contentMode = UIView.ContentMode.scaleAspectFill
        cover.clipsToBounds = true
        cover.isUserInteractionEnabled = true
        return cover
    }()
    
    
    var nameLabel: UILabel = {
        let titelLabel = UILabel()
        titelLabel.font = UIFont.boldSystemFont(ofSize: 17)
        titelLabel.textColor = .white
        titelLabel.text = "学习顾问"
        titelLabel.numberOfLines = 1
        return titelLabel
    }()
    
    var numbersleLabel: UILabel = {
        let titelLabel = UILabel()
        titelLabel.font = UIFont.systemFont(ofSize: 12)
        titelLabel.textColor = .white
        titelLabel.numberOfLines = 1
        
        
        return titelLabel
    }()
    
    var subtitleLabel: UILabel = {
        let titelLabel = UILabel()
        titelLabel.font = UIFont.systemFont(ofSize: 14)
        titelLabel.textColor = .white
        titelLabel.numberOfLines = 1
        
        
        return titelLabel
    }()
    
    
    
    var chatButton: UIButton = {
        let rightButton = UIButton(type: .custom)
        rightButton.setTitle("去对话", for: .normal)
        rightButton.layer.cornerRadius = 12
        rightButton.titleLabel?.font = UIFont.systemFont(ofSize: 13, weight: .semibold)
        rightButton.frame.size = CGSize(width: 68, height: 20)
        rightButton.backgroundColor = .primaryColor
        rightButton.isUserInteractionEnabled = false
//        rightButton.addTarget(self, action: #selector(handleRightBarButtonTapped(_:)), for: .touchUpInside)
        
        return rightButton
    }()
    
    
    
    
    @objc private func handleRightBarButtonTapped(_ sender: Any) {
        
    }
    
    @objc func chatTapped(tapGestureRecognizer: UITapGestureRecognizer)
    {
        //        delegate?.didTapChat(user: user)
    }
    override init(frame: CGRect) {
        super.init(frame: .zero)
        self.addSubview(nameLabel)
        self.addSubview(subtitleLabel)
        self.addSubview(avatarImageView)
        self.addSubview(chatButton)
        self.addSubview(numbersleLabel)
        self.backgroundColor = primaryBackgroundColor
        self.layer.cornerRadius = 12
        
       
        
        
       
        avatarImageView.snp.makeConstraints { make in
            make.top.equalTo(self).offset(8)
            make.left.equalTo(self).offset(16)
            make.width.equalTo(34)
            make.height.equalTo(34)
            
        }
        
        
        nameLabel.snp.makeConstraints { make in
            make.top.equalTo(avatarImageView)
            make.left.equalTo(avatarImageView.snp.right).offset(16)
            
            
        }
        
        numbersleLabel.snp.makeConstraints { make in
            make.top.equalTo(nameLabel.snp.bottom).offset(6)
            make.left.equalTo(nameLabel)
            
        }
        
        subtitleLabel.snp.makeConstraints { make in
            make.top.equalTo(numbersleLabel.snp.bottom).offset(8)
            make.left.equalTo(nameLabel)
            
        }
        
        chatButton.snp.makeConstraints { make in
            make.top.equalTo(avatarImageView)
            make.right.equalTo(self).offset(-16)
            make.width.equalTo(52)
            make.height.equalTo(24)
        }
       
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

